package dao

import (
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
)

type OpenInterfaceDao struct {
}

func NewOpenInterfaceDao() *OpenInterfaceDao {
	return &OpenInterfaceDao{}
}

func (d *OpenInterfaceDao) DeviceSnGetPlaceInfo(deviceSn string) *dingo.ErrorWrap {
	var id string

	db := global.Orm.Debug().Table("devices d").
		Select("p.hotel_id as id").
		Joins("left join places p on d.place_id = p.id").
		Where("d.device_sn = ?", deviceSn).Find(&id)

	return dingo.ErrorIf(db.Error, id)
}
